<?php if( $row->link ) : ?>
<a <?php echo $target;?> target="<?php echo $openTarget ;?>"  href="<?php echo $row->link;?>" title="<?php echo $row->title;?>">
<?php echo $row->mainImage;?>
</a>
<?php else: ?>
<?php echo $row->mainImage;?>
<?php endif; ?>